function alertAll(node,doNotShowNull){
	alert(objToString(node,doNotShowNull));
}

function objToString(node,doNotShowNull){
	var s = ""
	for(var x in node){
		var tmp = (typeof node[x]=="function"?"[function]":node[x]);
		if (tmp && tmp.length>100)
			tmp = tmp.substring(100);
		if (doNotShowNull && tmp == null)
			continue;
		s += x+":\t"+tmp+"\n"
		}
		return s;
}




/** 国际化,文件在app目录下  */
function I18N(){}
I18N.tokenMaps = {}
		
I18N.getText = function(token,defvalue){
	var locale = Cookie.read('locale')
	if (!locale) return defvalue
	var map = this.tokenMaps[locale]
	if (!map) return defvalue
	var v = map[token]
	if (!v) return defvalue
	else return v
	
}
var _isIE = null;
/* 根据某一个html元素id取得html元素对象 */
function $(element){
	if (typeof element == 'string' )
		return document.getElementById(element);
	else
		return element;
}

/* 根据html元素name取得多个html元素对象 */
function gname(name){
	return document.getElementsByName(name);
}

/* 去掉字符串首尾的空格 */
function trim(str){	
	return str?str.replace(/^\s*|\s*$/g,""):"";
}


/* Array的remove方法 */
Array.prototype.remove=function(dx){
	if(isNaN(dx)||dx>this.length){return false;}
	this.splice(dx,1);
}
/* Array的add方法 */
Array.prototype.add=function(dx,element){
	if (arguments.length == 1){
		this.push(dx)
	}else{
		if(isNaN(dx)||dx>this.length){return false;}
		var s2 = this.slice(dx);
		this[dx] = element;
		for (var i = 0;i<s2.length;i++){
			this[dx + i + 1] = s2[i]
		}
	}
}
/* 判断当前浏览器是否是ie */
function isIE(){
	if (_isIE==null){
		_isIE = false;
		if(navigator.appName == "Microsoft Internet Explorer")
			_isIE=true;
	}
	return _isIE;
}


/* 根据某个html节点的id，从html中删除该节点 */
function removeNodeById(oid){
	var tempObj=$(oid);
	if(tempObj)tempObj.parentNode.removeChild(tempObj);
}

/* 获取url中的参数 */
function getPara(para,s){
	var str = "";
	if(s == "" || s == null){
		str = document.location.href
	}
	else{
		str = s;
	}
	if(str.indexOf("?") == -1){
		return null;
	}
	else{
		str = str.substring(str.indexOf("?") + 1,str.length);
	}
	var params = str.split("&");
	
			
	for(var i=0;i<params.length;i++){
		if(params[i].indexOf(para + "=") == 0){
			return params[i].substring(params[i].indexOf("=") + 1,params[i].length);
		}
	}
}


/* 从dialog返回值 */
function backValue(value) {
	parent.parent.window.returnValue = value ;
	parent.parent.window.close();
}

function supportModalDialog(){
	return window.showModalDialog
}

/* 在dialog窗口中打开页面 */
function openDialogFrame(fileName,title,height,width,callback,resize){
	if (!supportModalDialog())
		window._dialogCallback = callback	// support firefox
	height = height + 20;
	if (fileName.charAt(0) == "/"){
		fileName = fileName.substring(1);
		fileName = appRoot + fileName;
	}
	var path = appRoot + "common/dialog.html?title="+title+"&src="+esc(fileName);
	var sobject = openDialog(path+(resize?"&scroll=no":""),window,height,width,"auto",resize);
	if (sobject && supportModalDialog() && callback){
		callback(sobject);
	}
	return sobject
}

/* 显示一个dialog窗口 */
function openDialog(path,strMessage,height,width,scroll,resize){
	var h,w,s,r;
	!height?h="200":h=height;
	!width?w="350":w=width;
	!scroll?s="no":s=scroll;
	!resize?r="no":r=resize;
	var f = "";
	if(supportModalDialog()){	
		f = "dialogHeight:"+h+"px;dialogWidth:"+w+"px;edge:Raised;center: Yes;help: no;resizable:"+r+";status: yes;scroll:"+s+";";
		return window.showModalDialog(path,strMessage,f);
	}
	else{
		f = "width="+w+",height="+h+",modal=yes,dialog=yes," + "left=" + getPopX(w) + ",top=" + getPopY(h);
		var dot = "?";
		if(path.indexOf("?") != -1)dot = "&";
		return window.open(path + dot + "msg=" + esc(strMessage),"",f);
	}
}
/* 获取dialog窗口的X坐标位置 */
function getPopX(width){
	return (screen.width - width)/2;
}
/* 获取dialog窗口的Y坐标位置 */
function getPopY(height){
	return ((screen.height - height)/2 - 100);
}

/* 提示错误的对话框 */
function showError(strMessage,height,width,scroll,resize){
	return openDialog(appRoot + "common/message.html?msgtype=error",strMessage,height,width,scroll,resize);
}

/* 提示信息的对话框 */
function showInformation(strMessage,height,width,scroll,resize){
	return openDialog(appRoot + "common/message.html?msgtype=information",strMessage,height,width,scroll,resize);
}
/* 提示可否的对话框 */
function showQuestion(strMessage,height,width,scroll,resize){
	return openDialog(appRoot + "common/message.html?msgtype=question",strMessage,height,width,scroll,resize);
	
}
/* 提示注意的对话框 */
function showWarning(strMessage,height,width,scroll,resize){
	return openDialog(appRoot + "common/message.html?msgtype=warning",strMessage,height,width,scroll,resize);
	
}


/* 调用日期控件 */
function showDatePicker(id){
	var obj = typeof id == "object"?id:$(id);
	var paras = appRoot + "common/date.html?tId=" + obj.id + "&tValue=" + obj.value;
	var defaultHeight = 225;
	if(obj.id.indexOf("AndTime") != -1){
		defaultHeight = 255;
	}
	var defaultWidth = 220;
	var dates = openDialog(paras,0,defaultHeight,defaultWidth);
	if ( dates != null && isIE()){
		obj.value = dates;
		obj.focus();
		obj.blur();
		obj.focus();
	}
}




/* 日期格式化:format="yyyy-MM-dd hh:mm:ss"; */
Date.prototype.format = function(format){
	if (!format)
		format = "yyyy-MM-dd"
	var o = {
		"M+" :  this.getMonth()+1,  //month
		"d+" :  this.getDate(),     //day
		"h+" :  this.getHours(),    //hour
		"m+" :  this.getMinutes(),  //minute
		"s+" :  this.getSeconds(), //second
		"q+" :  Math.floor((this.getMonth()+3)/3),  //quarter
		"S"  :  this.getMilliseconds() //millisecond
	}
	if(/(y+)/.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
	}
	for(var k in o) {
		if(new RegExp("("+ k +")").test(format)){
			format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
		}
	}
	return format;
}


String.prototype.replaceAll  = function(s1,s2){
	return this.replace(new RegExp(s1,"gm"),s2);
}


function clone(object){
	var obj = null;
	if (object instanceof Array){
		obj = [];
		for (var i=0;i<object.length;i++){
			var o = object[i];			
			if (o && typeof o == "object"){
				o = clone(o);
			}
			obj.push(o);
		}
	} else if(object instanceof Date){
		obj = object
	} else {
		obj = new Object();
		for (var prop in object){
			var o = object[prop];
			if (o && typeof o == "object"){
				o = clone(o);
			}
			obj[prop] = o;		
		}
	}
	return obj;
}

function returnToLogin(){
	try{
		//parent.parent.window.close();
		var p = Common._getRoot();
		if (p.pageType=="dialog"){
			p.close();
		}
		Common.wbWin.opener.document.location.href='../login.html';
		Common.wbWin.close();
	}catch(e){
		Common.wbWin.close();
	}
}

function Common(){}

/** 取半角字符长度 */
Common.getStrHalfLength = function(str){

	return str.replace(/[^\x00-\xff]/g,"**").length;
}

Common.getOptionsValue = function(options){
	var str = "";
	for(var i=0;i<options.length;i++){
		if(str != "")str += ",";
		str += options[i].value;
	}
	return str;
}
Common.addOption = function(obj,value,text){
	var opts = obj.options;
	for(var i=0;i<opts.length;i++){
		if(opts[i].value == value)
			return;
	}
	var o = new Option(text,value);
	obj[obj.options.length] = o;
}
Common.removeOption = function(obj){
	var list = [];
	var selectNo = 0;
	for(var i=0;i<obj.childNodes.length;i++){
		var ct = obj.childNodes[i];
		if (ct.selected){
			list.push(ct);
			selectNo++;
		}		
	}
	if(selectNo == 0)showWarning("请先选中需要删除的数据项");
	for(var i=0;i<list.length;i++){
		var c = list[i];
		obj.removeChild(c);
	}
}
Common.importOption = function(obj,dialogUrl,label,height,maxLength){
	var ov = Common.getOptionsValue(obj.options);
	var a = openDialogFrame(dialogUrl + "?orgId="+(Common.cOrg()).id + "&ids=" + ov,label,height,700);
	if(a){
		var op = "";
		if (maxLength && (a.length + obj.options.length) > maxLength){
			showError("选择数据超过允许数量("+maxLength + ")");
			return;
		}
		for(var i=0;i<a.length;i++){
			op = a[i];
			Common.addOption(obj,op[1],op[2]);
		}
	}
}
Common.initMultiSelect = function(targetId,label,formName,selectName,dialogUrl,height,maxLen){
	var obj = $(targetId);
	if (!obj) return;

	obj.innerHTML = Common.getMultiSelectHtml(label,formName,selectName,dialogUrl,height,maxLen);
}

Common.getMultiSelectHtml = function(label,formName,selectName,dialogUrl,height,maxLen){
	
	var str = "<table cellspacing=0 cellpadding=0 border=0>";
		str += "<tr><td valign=top style='padding-top:5px;width:100px;'><label>"+label+"</label></td>";
		str += "<td valign=top><select multiple name='"+selectName+"' style='height:100px;margin:0px;width:130px'>";
		str += "</select></td><td valign=top>";
		str += "<button type='button' onclick=\"Common.importOption($('"+formName+"')['"+selectName+"'],'"+dialogUrl+"','"+label+"',"+height+","+maxLen+")\"><img src='../images/basic/button_add.gif' border=0></button>";
		str += "<br><button type='button' onclick=\"Common.removeOption($('"+formName+"')['"+selectName+"'])\"><img src='../images/basic/button_remove.gif' border=0></button>";
		str += "</td></tr></table>";
	return str;
}

Common.getValues = function(form) {
	if(typeof form=="string")
		form = $(form);
	var eles = form.elements;
	var key,value,formMap={};
	for(var i=0; i<eles.length;i++){
		key = eles[i].name?eles[i].name:eles[i].id;
		value = Common.getValue(eles[i]);
		if (key != null && key != "" ){
			if(!formMap[key]){
				formMap[key] = value;
			}
			else{
				if(value != "")
					formMap[key] += ","+ value;
			}
		}
	}
	return formMap;
}
Common.getValue = function(ele){
	if(this._isHTMLElement(ele,"select")){
		if(ele.multiple == true){
			return Common.getOptionsValue(ele);
		}
		else{
			return ele.value;
		}
	}
	if(this._isHTMLElement(ele,"input")){
		if(ele.type == "radio" || ele.type == "checkbox"){
			if(ele.checked)return ele.value;
		}
		else{
			return ele.value;
		}
	}
	if (this._isHTMLElement(ele,"textarea")){
		return ele.value;
	}
	return "";
}
Common.showDetail = function(node,obj,tagName){
	if (typeof node=="string")
		node = $(node);
	if (!node){alert("Common.showDetail:null error");return;}
	if (!tagName) tagName = "SPAN";
	var nodes = node.getElementsByTagName(tagName);
	for (var i = 0;nodes&&i<nodes.length;i++){
		var n = nodes[i];
		var prop = null;
		if (n.name) prop = n.name;
		else if (n.id) prop = n.id;
		else continue;
		var text = obj[prop];
		if (n.tagName=="SPAN"||n.tagName=="DIV"||n.tagName=="P"){
			if (text instanceof Date){
				text = text.format();
			}
			n.innerHTML = text||text==0?text:"";
		}
	}
}
Common.setValues = function(form,values) {
	if (typeof form == "string")
		form = $(form);
	if (!form){alert("Common.setValues:null error");return;}
	var dealed={};	
	for (var i = 0; i < form.elements.length; i++) {
		if (form[i].tagName=="FIELDSET"||form[i].type=="button") continue;		
		if (form[i].name != null) prop = form[i].name;
		else if (form[i].id != null) prop = form[i].id;
		if (dealed[prop])
			continue;
		if (prop!=null&&prop!='')
		{	
			Common.setValue(form[prop],values[prop]);
			dealed[prop] = true;
		}
	}	
}
Common.setValue = function(ele, val) {
	if (val == null) val = "";
	if (val instanceof Date)
	{
		val = val.format();
	}
	if (this._isHTMLElement(ele, "select")) {
		if (ele.type == "select-multiple" && Common._isArray(val)) {
			this._selectListItems(ele, val);
		}
		else {
			this._selectListItem(ele, val);
		}
		return;
	}
	var obj = ele[0]?ele[0]:ele;
	val = val.toString();
	
	if (this._isHTMLElement(obj, "input")) {
		if (obj.type == "radio") {
	
			if (ele.length > 1) {
				var node;
				for (i = 0; i < ele.length; i++) {
					node = ele[i];
					if (node.type == "radio") {
						node.checked = (node.value == val);
					}
				}
			}
			else {
				ele.checked = (val == true);
			}
		}
		else if (obj.type == "checkbox") {
			ele.checked = val;
		}
		else {
			ele.value = val;
		}
		return;
	}

	if (this._isHTMLElement(ele, "textarea")) {
		ele.value = val;
		return;
	}
}
Common._selectListItems = function(ele, val) {
	var found  = false;
	var i;
	var j;
	for (i = 0; i < ele.options.length; i++) {
		ele.options[i].selected = false;
		for (j = 0; j < val.length; j++) {
			if (ele.options[i].value == val[j]) {
				ele.options[i].selected = true;
			}
		}
	}
	if (found) return;
	for (i = 0; i < ele.options.length; i++) {
		for (j = 0; j < val.length; j++) {
			if (ele.options[i].text == val[j]) {
				ele.options[i].selected = true;
			}
		}
	}
}

Common._isArray = function(data) {
	return (data && data.join) ? true : false;
};

Common._selectListItem = function(ele, val) {

	var found  = false;
	var i;
	for (i = 0; i < ele.options.length; i++) {
		if (ele.options[i].value == val) {
			ele.options[i].selected = true;
			found = true;
		}
		else {
			ele.options[i].selected = false;
		}
	}
	
	if (found) return;
	
	for (i = 0; i < ele.options.length; i++) {
		if (ele.options[i].text == val) {
			ele.options[i].selected = true;
		}
		else {
			ele.options[i].selected = false;
		}
	}
}

Common._isHTMLElement = function(ele, nodeName) {
	if (ele == null || typeof ele != "object" || ele.nodeName == null) {
		return false;
	}
	
	if (nodeName != null) {
		var test = ele.nodeName.toLowerCase();
		
		if (typeof nodeName == "string") {
			return test == nodeName.toLowerCase();
		}
		
		return false;
	}
	
	return true;
}
Common.getRadio = function(radioName){
	if (!radioName) radioName = "radios";
	var radios = document.getElementsByName(radioName);
	for (var i=0;i<radios.length;i++){
		var radio = radios[i];
		if (radio.checked){
			return radio;
		}
	}
	return null;
}
Common.getRadioValue = function(radioName){
	var radio = Common.getRadio(radioName);
	return radio?radio.value:null;
}
Common.getCheckBoxValue = function(checkName){
	if (!checkName) checkName = "checkboxs";
	var cs = document.getElementsByName(checkName);
	var ids = "";
	for (var i=0;i<cs.length;i++){
		var cb = cs[i];
		if (cb.checked){
			if (ids) ids += ",";
			ids += cb.value;
		}
	}
	return ids;	
}


Common.initBoxOrRadio = function(area,options){
	if (options.list&&options.list.length>0)
		Common._initBoxOrRadio(area,options);
	else if (options.sql){
		DWR.call("ejbQueryService.findData",options.sql,options.params,function(result){
			options.list = result.objects;
			Common._initBoxOrRadio(area,options);
			if (options.callback)
				options.callback(result);
		});
	}		
} 
Common._initBoxOrRadio = function(area,options){	
	if (typeof area == "string") area = $(area);
	if (!area){alert("Common.initCheckboxs:null error");return;}
	var list = options.list;
	var boxName = options.boxName?options.boxName:area.id;
	var name = options.name?options.name:"name"
	var value = options.value?options.value:"value"
	var type = options.isRadio?"radio":"checkbox"
	var ckmap = {}
	if (options.defChecked){
		if (options.defChecked instanceof Array){
			for (var i=0;i<options.defChecked.length;i++){
				ckmap[options.defChecked[i]] = true
			}
		}else{
			ckmap[options.defChecked] = true
		}		
	}
	var html = ""
	for (var i=0;i<list.length;i++){
		var b = list[i];
		html += "<input type="+type+" name='"+boxName+"' value='"+b[value]+"'"+(ckmap[b[value]]?" checked":"")+">" + b[name] +" "
	}
	area.innerHTML = html;
}

Common.initDict = function(select,dictType,nullLabel,code,text){
	if (!select) return;
	var options = {
				list:dictType instanceof Array? dictType:Common.getItems(dictType)
			}
	if (nullLabel)
		options.nullLabel = nullLabel;
	if (code)
		options.code = code;
	if (text)
		options.text = text;
	Common._initSelect(select,options);	
}


Common.initSql = function(select,sqlName,params,code,text,nullLabel,callback){
	var options = {
		code:code?code:"0",
		text:text?text:"1",
		nullLabel:nullLabel
	}
	
	DWR.call("ejbQueryService.findData",sqlName,params,function(result){
			options.list = result;
			Common._initSelect(select,options);
			if (callback)
				callback(result);
		});
}

Common._initSelect = function(select,obj){
	if (typeof select == "string")
		select = $(select);
	if (!select){alert("Common.initSelect:null error");return;}
	select.options.length=0;
	if (obj.onchange)
		select.onchange = obj.onchange;
	if (obj.nullLabel)
		select.options[select.options.length]=new Option(obj.nullLabel,'');
	if (!obj.list) return;
	var code = obj.code||obj.code==0?obj.code:'code';
	var text = obj.text?obj.text:'text';
	for (var i=0;i<obj.list.length;i++){
		var optv = obj.list[i];
		var codes = "";
		if (code instanceof Array){
		
			for (var c=0;c<code.length;c++){
				if (codes)
					codes += ",";
				codes += optv[code[c]];
			}	
		}else
			codes = optv[code];
		select.options[select.options.length]=new Option(optv[text],codes);
			
		if (obj.defText==optv[text]||(obj.defCode&&obj.defCode==optv[code])){
			select.selectedIndex = select.options.length-1;
		}
	}
	if (obj.disabled)
		Common.selectDisabled(select);
}

Common.selectDisabled = function(select,disabled,value){
	if (disabled==null) disabled=true;
	if (value){
		for (var i=0;i<select.childNodes.length;i++){
			var opt = select.childNodes[i]
			if (opt.value==value)
				opt.selected = true;
			else
				opt.selected = false;
		}
	}
	select.disabled = disabled;
	select.style.background = disabled?'#FFFFCC':'#FFF';
}

Common.getText = function(dict,code){

	var item = this.getItem(dict,code)
	return item==null?null:item.text
}

Common.getItem = function(dict,code){

	var itemMap = this._getItemMap(dict)
	if (!itemMap) return;
	
	return itemMap[code]
}

Common.getSubsetItems = function(dict,codes){
	var itemMap = this._getItemMap(dict)
	if (!itemMap) return;
	
	var list = [];
	for(var i=0;i<codes.length;i++){
		if (itemMap[codes[i]])
			list.push(itemMap[codes[i]]);
	}
	return list;
}

Common._getItemMap = function(dict){
	if (!dict) return;
	var localCache = this.getLocalCache()

	var itemMap = localCache['dict_m_'+dict];
	
	if (!itemMap){
		
		this._loadDict(dict)
		
		itemMap = localCache['dict_m_'+dict];
	}	
	
	return itemMap
}

//得到浏览器本地缓存，目前存在workbench对象中
Common.getLocalCache = function(){
	var cache = this.wbWin.localCache;
	if (!cache)
	{
		cache = {}
		this.wbWin.localCache = cache
	}
	return cache;
	
}

Common.specialDicts = {}

/** 可以定义特殊的dict和它的reloadFunc ,例如帐户类型*/
Common.registerSpecialDict = function(dict,reloadFunc){
	Common.specialDicts[dict] = reloadFunc
}

Common.getItems = function(dict,codes){
	if (!dict) return;
	var localCache = this.getLocalCache()

	var itemList = localCache['dict_l_'+dict];
	if (!itemList){
		
		this._loadDict(dict)
		
		itemList = localCache['dict_l_'+dict];
	}	
	
	return itemList;
}

	
Common._loadDict = function(dict){

	var localCache = this.getLocalCache()
	
	var specialLoadFunc = Common.specialDicts[dict]
	var items 
	if (specialLoadFunc)
		items = specialLoadFunc();
	else
		items = DWR.syncCall("loginService.getDictItems",dict);
	var map = {};
	var item;
	for(var i=0;i<items.length;i++) {
		item = items[i];
		map[item.code] = item;
	}
	itemList = items;
	localCache['dict_l_'+dict]=items;
	localCache['dict_m_'+dict]=map;
}

Common.clearDict = function(dict){
	var localCache = this.getLocalCache()
	localCache['dict_l_'+dict]=null;
	localCache['dict_m_'+dict]=null;
}
Common.cOrg = function(){
	var org = this.getLocalCache()['cOrg']
	return clone(org);//{id:org.id,uniqueId:org.uniqueId,name:org.name,orgLevel:org.orgLevel,parent:org.parent,isInternal:org.isInternal}
}
Common.rootOrg = function(){
	var org = this.getLocalCache()['rootOrg']
	return clone(org);//{id:org.id,uniqueId:org.uniqueId,name:org.name,orgLevel:org.orgLevel,parent:org.parent,isInternal:org.isInternal}
}


Common.getMaxResult = function(){
	var localCache = this.getLocalCache()
	var token = 'queryTable.maxResult'
	var maxResult = localCache[token]
	if (!maxResult){
		var v = DWR.syncCall("propertyService.getSystemPropertyValue","magicTableLength");
		maxResult = v ? v : 10;
		localCache[token] = maxResult
	}
	return maxResult;
}

Common.cOperator = function(){
	var person = this.getLocalCache()['cOper']
	return {id:person.id,name:person.name,uniqueId:person.uniqueId};
}

Common._getRoot = function(p){
	if (!p)
		p = window;
	p.id = "ID"+Math.random();
	var pageId = null;
	var count = 0;
	while(p.id!=pageId){
		pageId = p.id;
		p = p.parent;
		if (!p.id)
			p.id = "ID"+Math.random();		
		if (count<8)
			count++;
		else
			break;
	}
	return p;
}

Common._getWB =function(p){
	p = this._getRoot(p);
	if (p.pageType=="dialog"){
		return this._getWB(p.dialogArguments);
	}
	return p;
}
Common._getOpener = function (){
	var p = this._getRoot();
	if (p.pageType=="dialog")
		return p.dialogArguments;
	else
		return null;	
}


Common.getPhoto = function (link){

	if (!link) return appRoot + "images/basic/blank.gif";
	return contextRoot + "d/photo/"+link;
}


function setPages(pages){
	window._switch_pages = pages
}

function switchPage(pageId,handle){
	if (!window._switch_pages) return;
	for (var i=0;i<window._switch_pages.length;i++){
		var c = $(window._switch_pages[i]);
		if (!c) continue;
		if (c.id == pageId){
			c.style.display = "";
		}else{
			c.style.display = "none";
		}
	}
	if (typeof handle=="function"){
		handle();
	}
}
try{
	Common.wbWin = function(){return Common._getWB()}();
	Common.opWin = function(){return Common._getOpener()}();
}catch(e){}


//dialog back value function
function dialogBackValue(v){
	if(isIE()){
		parent.backValue(v);
	}
	else{
        if(parent.opener._dialogCallback){
            parent.opener._dialogCallback(v);
        }
        parent.close();
	}
}
//获得form中的按钮
function findBtns(form){
	var bts = [];
    for (var i = 0;i<form.elements.length;i++){
    	var e = form.elements[i];
    	if (e.type == "button")
    		bts.push(e);
    }
    return bts
}
function killChild(child){
	if (typeof child != "object")
		child = $(child);
	var p = child.parentNode;
	p.removeChild(child);	
}
function killChildren(parentNode){
	if (typeof parentNode !="object")
		parentNode = $(parentNode)
	while(parentNode.childNodes.length>0){
		var c = parentNode.childNodes[0]
		parentNode.removeChild(c)
	}
}




	
/** 取得绝对位置
 * @param e dom对象
 */
function absp(e){							//取绝对位置方法
    var t=e.offsetTop;   
    var l=e.offsetLeft;   
    while((e=e.offsetParent)){   
    	t+=e.offsetTop;   
    	l+=e.offsetLeft;   
	}
	return {top:t,left:l}   
}




/** 为对象绑定方法
 * @param node dom对象
 * @param action 
 * @param func 方法 
 */
function bind(node,action,func){
	if (typeof node != "object")
		node = $(node)
	if (!node) return;
	node["on"+action] = func;
}
/** 为对象绑定方法
 * @param node dom对象
 * @param func 方法 
 */
function bindClick(node,func){
	bind(node,"click",func)
}


//弹出窗口，选择数据
function spellUrl(url,opts){
	if (!opts) return url
	var params = ""
	for (var prop in opts){
		if(typeof opts[prop] != "function"){
			var v = opts[prop];
			if (!v && v != false && v != 0) continue;
			if (!params) 
				params += "?"
			else
				params += "&"
			params += prop+"="+v;
		}
	}
	return url + params;
}

Common.rootWin = function(p){
	if (!p)
		p = window;
	while(p.parent != p){
		p = p.parent
	}
	return p
}
Common.getOpener = function (){
	var p = Common.rootWin();
	return p.opener?p.opener:p.dialogArguments	
}
